use "$temp/acs_longform_merged_clean", clear
keep if dby>=1990 //restrict to at-risk sample

tab age_group parent_inc_quart
replace coll = 0 if age_group == 1

ren state_2000 stfip
merge m:1 stfip using "$data/Other/state_region_xwalk", keep(match) nogen
ren stfip state_2000

ren cz temp
ren cz_2000 cz
merge m:1 cz using "$temp/cz_hpi_shocks"
ren cz cz_2000
ren temp cz
replace shock_hpi_2009 = shock_hpi_2009*-1
replace shock_hpi_2012 = shock_hpi_2012*-1
su shock_hpi_2009 [w=weight]
replace shock_hpi_2009 = `r(mean)' if shock_hpi_2009 == . //little fix here.


************hpi shocks
gen hpi_age_dum_1 = (age_group==1)*shock_hpi_2009
gen hpi_age_dum_2 = (age_group==2)*shock_hpi_2009
gen hpi_age_dum_3 = (age_group==3)*shock_hpi_2009
gen hpi_age_dum_4 = (age_group==4)*shock_hpi_2009

forval q = 1/4{
	local controls `"shock_hpi_2009 sex asian black hispan i.age_group i.state_2000#i.head_coll i.year head_mar head_constr_manu house_value parent_inc own_house"'
	reg coll hpi_age_dum* `controls' [aw = weight] if parent_inc_quart == `q', vce(cluster cz_2000)

	//store estimates
	forval i = 1/4{
		local effect_`i'_`q' = _b[hpi_age_dum_`i']
		local se_`i'_`q' = _se[hpi_age_dum_`i']
		su coll [aw = weight] if age_group == `i' & parent_inc_quart == `q'
		local mean_`i'_`q' = `r(mean)'
	}
}

//create data for graphing
preserve
clear
set obs 16
gen group = .
gen effect = .
gen se = .
gen mean = .
gen quart = .
forval q = 1/4{
	forval i = 1/4{
		local line = (`q'-1)*4 + `i'
		replace quart = `q' in `line'
		replace group = `i' in `line'
		replace effect = `effect_`i'_`q'' in `line'
		replace se = `se_`i'_`q'' in `line'
		replace mean = `mean_`i'_`q'' in `line'
	}
}
	
keep if group == 4	
gen effect_pct = (effect/mean)*100
gen se_pct = (se/mean)*100
serrbar effect_pct se_pct quart, scale(1.96) bgcolor(white) graphregion(color(white)) ///
ytitle("Percentage Effect, Age 26-28") xlabel(1 "1" 2 "2" 3 "3" 4 "4") xtitle("Parent Income Quartile") yline(0)
graph export "$disc/6_effects_coll_hpi.png", replace width(1500)
restore




exit

